package script;

import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;

public class OPeratorExprSample {

    public static void main(String[] args) {

        ExpressionParser parser = new SpelExpressionParser();

        boolean trueValue = parser.parseExpression("2 == 2").getValue(Boolean.class);
        System.out.println(trueValue);


        boolean falseValue = parser.parseExpression("2 < -0.5").getValue(Boolean.class);
        System.out.println(falseValue);

        trueValue = parser.parseExpression("\"back\" < \"block\"").getValue(Boolean.class);
        System.out.println(trueValue);


        falseValue = parser.parseExpression("'xyz' instanceof T(int)").getValue(Boolean.class);
        System.out.println(falseValue);

        trueValue = parser.parseExpression("'5.00' matches '^-?\\d+(\\.\\d{2})?$'").getValue(Boolean.class);
        System.out.println(trueValue);

        falseValue = parser.parseExpression("'5.0067' matches '\\^-?\\d+(\\.\\d{2})?$'").getValue(Boolean.class);
        System.out.println(trueValue);




        int two = parser.parseExpression("1 + 1").getValue(Integer.class);
        System.out.println(two);

        String testStr = parser.parseExpression("'testString' + '123'").getValue(String.class);
        System.out.println(testStr);

        int four = parser.parseExpression("1 - -3").getValue(Integer.class);
        System.out.println(four);

        int six = parser.parseExpression("-2 * -3").getValue(Integer.class);
        System.out.println(six);

        double twentyFour = ((SpelExpressionParser) parser).parseRaw("2.0 * 3e0 * 4").getValue(double.class);
        System.out.println(twentyFour);

        int miusTwo = ((SpelExpressionParser) parser).parseRaw("6 / -3").getValue(Integer.class);
        System.out.println(miusTwo);

        double one = parser.parseExpression("8.0 / 4e0 /2").getValue(Double.class);
        System.out.println(one);

        int three = parser.parseExpression("7 % 4").getValue(Integer.class);
        System.out.println(three);

        one = parser.parseExpression("8 / 5 % 2").getValue(Integer.class);
        System.out.println(one);

        int minusTwentyOne = parser.parseExpression("1+2-3*8").getValue(Integer.class);
        System.out.println(minusTwentyOne);
    }


}
